package 力扣;

import sun.applet.Main;


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author yyq
 * @create 2022-04-08 9:26
 */
public class leetcode101 {
    public static void main(String[] args) {
        TreeNode root=new TreeNode(1);
        root.left=new TreeNode(2);
        root.left.right=new TreeNode(3);
        root.right=new TreeNode(2);
        root.right.right=new TreeNode(3);
        System.out.println(isSymmetric(root));
    }

    public static boolean isSymmetric(TreeNode root) {
        if(root==null) return false;
        if(root.left==null&&root.right==null)return true;
        TreeNode left = root.left;
        TreeNode right = root.right;
        if(left==null&&right!=null) return false;
        if(right==null&&left!=null) return false;
        int[] flag=new int[1];
        flag[0] = 1;
        invertTree(left);
        preOrderadvanced(left,right,flag);
        if(flag[0] == 1)return true;
        else return false;



    }
    public static TreeNode invertTree(TreeNode root) {
        if(root==null) return root;
        preOrderInvert(root);
        return root;
    }
    private static void preOrderInvert(TreeNode root) {
        if(root==null) return;
        TreeNode temp=root.left;
        root.left=root.right;
        root.right=temp;

        if(root.left!=null) preOrderInvert(root.left);
        if(root.right!=null) preOrderInvert(root.right);
    }


    static void  preOrder(TreeNode root,ArrayList<Integer> list){
        if(root==null) return;
        list.add(root.val);

        if(root.left!=null) preOrder(root.left,list);
        else list.add(null);
        if(root.right!=null) preOrder(root.right,list);
        else list.add(null);
    }

    static void   preOrderadvanced(TreeNode left,TreeNode right,int[] flag){
        if(left.val!=right.val) {
            flag[0] =0;
            return;
        }

        if(left.left!=null&&right.left!=null){
            preOrderadvanced(left.left,right.left,flag);
        }else {
            if(left.left ==null){
                if(right.left!=null) {
                    flag[0] = 0;
                    return;
                }
            }
            if(right.left == null){
                if(left.left!=null) {
                    flag[0] = 0;
                    return;
                }
            }
        }
        if(left.right!=null&&right.right!=null){
            preOrderadvanced(left.right,right.right,flag);
        }else {
            if(left.right ==null){
                if(right.right!=null) {
                    flag[0] = 0;
                    return;
                }
            }
            if(right.right == null){
                if(left.right!=null) {
                    flag[0] = 0;
                    return;
                }
            }
        }

    }




}
